import router from "@/router/index";
export const to2 = async () => {
  window.localStorage.setItem("token", "");
  await router.push("/login");
  location.reload();
};

export const loadRemoteComponent = async (url: string): Promise<any> => {
  return new Promise((resolve, reject) => {
    const script = document.createElement("script");
    const regex = /\/remote\/(\w+)/;
    const matchResult = url.match(regex);
    if (matchResult && matchResult.length > 0) {
      const comName = matchResult[1] as string;
      script.src = url;
      script.onload = (val) => {
        // console.log(val);
        resolve(window[comName]);
      };
      script.onerror = () => {
        reject(new Error("Failed to load remote component"));
      };
      document.head.appendChild(script);
    }
  });
};
